import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      home: Scaffold(
        appBar: AppBar(
          title: Text('TextField'),
        ),
        body: HomePage(),
      ),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final userNameTextEditController = TextEditingController();
  final pwdNameTextEditController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Column(
        children: <Widget>[
          SizedBox(
            height: 5,
          ),
          Theme(
            data: ThemeData(
              primaryColor: Colors.red,
            ),
            child: TextField(
              controller: userNameTextEditController,
              decoration: InputDecoration(
//                labelText: "用户名",
                hintText: "请输入",
                icon: Icon(Icons.people),
                contentPadding: EdgeInsets.all(5),
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(15.0),
                ),
                enabledBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Colors.orange),
                ),
                focusedBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Colors.red),
                ),
//                filled: true,
//                fillColor: Colors.red[100],
              ),
              onChanged: (value) {
                print(value);
              },
              onSubmitted: (value) {
                print("onSubmitted" + value);
              },
            ),
          ),
          SizedBox(
            height: 5,
          ),
          TextField(
            controller: pwdNameTextEditController,
            decoration: InputDecoration(
//              labelText: "password",
              hintText: "password",
              icon: Icon(Icons.people),
              contentPadding: EdgeInsets.all(5),
              border: OutlineInputBorder(),
              filled: false,
              fillColor: Colors.red[100],
              enabledBorder: UnderlineInputBorder(
                borderSide: BorderSide(color: Colors.orange),
              ),
              focusedBorder: UnderlineInputBorder(
                borderSide: BorderSide(color: Colors.red),
              ),
            ),
            onChanged: (value) {
              print(value);
            },
            onSubmitted: (value) {
              print("onSubmitted" + value);
            },
          ),
          SizedBox(
            height: 5,
          ),
          Container(
            width: double.infinity,
            height: 52,
            child: FlatButton(
              child: Text(
                "登 录",
                style: TextStyle(fontSize: 20, color: Colors.white),
              ),
              onPressed: () {
//1.获取用户名和密码
                final userName = userNameTextEditController.text;
                final pwd = pwdNameTextEditController.text;
                print("账号：" + userName + "密码：" + pwd);
              },
              color: Colors.lightBlue,
            ),
          )
        ],
      ),
    );
  }
}
